Spring Boot
In this lesson, we'll be starting the discussion about the Spring Boot framework.
We'll cover the following
The Spring framework and the Java community#
The Spring Framework has long been part of the Java community. It has a broad set of features covering most of the technical requirements of typical Java applications. Spring Boot facilitates the use of Spring.
A minimal Spring Boot application can be found in the directory simplest-spring-boot of the project https://github.com/ewolff/spring-boot-demos.
Java code#
The Java code from the project shows how Spring Boot can be used.
Line 5 and 7:
- The annotation
@RestController
means that the classControllerAndMain
should process HTTP requests.
Line 6:
@SpringBootApplication
triggers the automatic configuration of the environment.
The application thereby starts an environment with a web server and with the parts of the Spring framework that are fitting for a web application.
Line 9:
- The method
hello()
, is annotated with@RequestMapping
. Therefore it is called upon an HTTP request to the URL"/"
. The method’s return value is returned in the HTTP response.
Lines 13 and 14:
- Finally, the
main()
method starts the application with the help of the classSpringApplication
. - The application can simply be started as a Java application even though it processes HTTP requests.
Note: A web server is required for handling HTTP in the Java world. It is included in the application.
The build configuration inherits settings from the parent configuration spring-boot-starter-parent
.
Maven’s parent configuration makes it easy to reuse settings for the build of multiple projects.
The version of the Maven parent determines which version of Spring Boot is used.
The Spring Boot version defines the version of the Spring framework and the versions of all other libraries.
Thus, the developer does not have to define a stack with compatible versions of all frameworks, which is otherwise, often a challenge.
Q U I Z
The version of the Maven parent indirectly determines which version of Spring Boot is used.
A)
True
B)
False
In the next lesson, we’ll look at how the Spring Boot starter web can serve as a single web dependency.